wordpress how to check is post or page

How to check if the current request is for the post  ?

 

You can check if the current request is for for post using wordpress function is_singel().

Example

is_single( '17' )

When Post 17 is being displayed as a single Post.
is_single( ‘Irish Stew’ )
When the Post with Title “Irish Stew” is being displayed as a single Post.

is_single( 'beef-stew' )

When the Post with Post Slug “beef-stew” is being displayed as a single Post.

is_single( array( 17, 'beef-stew', 'Irish Stew' ) ) 
Returns true when the single post being displayed is either post ID 17, or the post_name is "beef-stew", or the post_title is "Irish Stew".

is_single( array( 17, 19, 1, 11 ) )
Returns true when the single post being displayed is either post ID = 17, post ID = 19, post ID = 1 or post ID = 11.

is_single( array( ‘beef-stew’, ‘pea-soup’, ‘chili’ ) )
Returns true when the single post being displayed is either the post_name “beef-stew”, post_name “pea-soup” or post_name “chili”.

How to check if the current request is for the Page ?

You can check if the current request is for for post using wordpress function is_page().

Example


is_page() 
When any Page is being displayed.

is_page( ’42’ )
When Page 42 (ID) is being displayed.

is_page( ‘About Me And Joe’ )
When the Page with a post_title of “About Me And Joe” is being displayed.

is_page( ‘about-me’ )
When the Page with a post_name (slug) of “about-me” is being displayed.

is_page( array( 42, ‘about-me’, ‘About Me And Joe’ ) )
Returns true when the Pages displayed is either post ID = 42, or post_name is “about-me”, or post_title is “About Me And Joe”.

is_page( array( 42, 54, 6 ) )
Returns true when the Pages displayed is either post ID = 42, or post ID = 54, or post ID = 6.